﻿using System.Runtime.CompilerServices;
using LinqExample;

List<Employee> employees = new List<Employee>()
{
    new Employee() { EmpId = 101, EmpName = "Henry", Job = "Designer", City = "SH" },
    new Employee() { EmpId = 102, EmpName = "Jack", Job = "Developer", City = "Shanghai" },
    new Employee() { EmpId = 103, EmpName = "Gabriel", Job = "Designer", City = "Beijing" },
    new Employee() { EmpId = 104, EmpName = "Alexa", Job = "Manager", City = "New York" },
};

var result = employees.Where(x => x.EmpId == 101);
foreach (Employee item in result)
{
    Console.WriteLine(item.EmpId);
    Console.WriteLine(item.EmpName);
}

// OrderBy
IOrderedEnumerable<Employee> sortedEmployees = employees.OrderBy(emp => emp.City);

// First or FirstOrDefault
Employee firstEmps = employees.FirstOrDefault(x => x.Job == "Designer");

// Last or LastOrDefault
Employee lastEmps = employees.Last(x => x.Job=="Designer");

// ElementAt or ElementAtOrDefault
Employee eleEmployee = employees.Where(x => x.Job == "Designer").ElementAtOrDefault(1);

// Single and SingleOrDefault
Employee singleEmp = employees.Single(x => x.Job == "Designer");


Console.ReadKey();